import { CallHandler, ExecutionContext, Injectable, NestInterceptor, } from '@nestjs/common'
import { Reflector } from '@nestjs/core'
import { Observable, map } from 'rxjs'

@Injectable()
export class TransformInterceptor implements NestInterceptor {
  constructor(private readonly reflector: Reflector) { }

  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    return next.handle().pipe(
      map((data) => {
        // const pure = this.reflector.get<boolean>(RETURN_PURE_KEY, context.getHandler())
        // const msg = this.reflector.get<string>(RETURN_MSG_KEY, context.getHandler()) ?? defaultReturnMsg

        return data?.resultData ? { ...data?.resultData } : data
      }),
    )
  }
}
